﻿using SWEN3Application.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SWEN3Application
{
    public partial class StaffManagement : MasterForm
    {
        public StaffManagement()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void createBtn_Click(object sender, EventArgs e)
        {
            Staffs st = new Staffs(Convert.ToInt32(tbxStaffID.Text), tbxStaffName.Text, tbxHomeAddress.Text, Convert.ToInt32(tbxContactNo.Text), Convert.ToInt32(tbxBankNo.Text), DateTime.Parse(dateTimePicker1.Text), cbDutyType.Text);
            StaffsDBManager sm = new StaffsDBManager();
            if (sm.createStaff(st) == 1)
            {
                label1.Text = "Staff Created Successful!";
            }

        }

        private void StaffManagement_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sWEN3DatabaseSystemDataSet7.Staffs' table. You can move, or remove it, as needed.
            this.staffsTableAdapter1.Fill(this.sWEN3DatabaseSystemDataSet7.Staffs);
            // TODO: This line of code loads data into the 'sWEN3DatabaseSystemDataSet6.Staffs' table. You can move, or remove it, as needed.
            this.staffsTableAdapter.Fill(this.sWEN3DatabaseSystemDataSet6.Staffs);

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            StaffsDBManager smdb = new StaffsDBManager();
            if (smdb.DeleteStaff(Convert.ToInt32(cbDeleteStaff.Text)) == 1)
            {
                StaffManagement sm = new StaffManagement();
                sm.Show();
                this.Hide();
            }       
        }

        private void cbSearchStaff_SelectedIndexChanged(object sender, EventArgs e)
        {
            StaffsDBManager smdb = new StaffsDBManager();
            Staffs st = new Staffs();
            st = smdb.GetStaffsById(Convert.ToInt32(cbSearchStaff.Text));
            if (st != null)
            {
                lblStaffid.Text = st.StaffId.ToString();
                lblStaffName.Text = st.StaffName.ToString();
                lblStaffContact.Text = st.StaffContact.ToString();
                lblStaffAddress.Text = st.StaffAddress.ToString();
                lblBankNo.Text = st.BankNo.ToString();
                lblDOB.Text = st.DOB.ToString();
                lblDutyType.Text = st.DutyType.ToString();
            }
        }

        private void tabControl2_Click(object sender, EventArgs e)
        {
            StaffsDBManager smdb = new StaffsDBManager();
            Staffs st = new Staffs();
            st = smdb.GetStaffsById(Convert.ToInt32(cbSearchStaff.Text));
            if (st != null)
            {
                lblStaffid.Text = st.StaffId.ToString();
                lblStaffName.Text = st.StaffName.ToString();
                lblStaffContact.Text = st.StaffContact.ToString();
                lblStaffAddress.Text = st.StaffAddress.ToString();
                lblBankNo.Text = st.BankNo.ToString();
                lblDOB.Text = st.DOB.ToString();
                lblDutyType.Text = st.DutyType.ToString();
            }
        }
    }
}
